package com.student.controller;

import com.student.pojo.Classes;
import com.student.service.ClassesService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
/**
 * @author 是一个鸽子啊
 * @date 2020/4/14
 * @qq 364826415
 */
@Controller
public class ClassesController {
    @Autowired
    @Qualifier("classesServiceImpl")
    private ClassesService classesService;
    @RequestMapping("/queryClasses")
    private String queryClasses(HttpServletRequest request){
        List<Classes> classesList = classesService.queryClasses();
        request.setAttribute("classesList",classesList);
        return "/class-table";
    }
    @RequestMapping("/addClasses")
    private String addClasses(Classes classes,HttpServletRequest request){
        classesService.addClasses(classes);
        List<Classes> classesList = classesService.queryClasses();
        request.setAttribute("classesList",classesList);
        return "/class-table";
    }
    @RequestMapping("/updateClasses")
    private String updateClasses(Classes classes,HttpServletRequest request){
        classesService.updateClasses(classes);
        List<Classes> classesList = classesService.queryClasses();
        request.setAttribute("classesList",classesList);
        return "/class-table";
    }
    @RequestMapping("/queryClassesByName")
    private String queryClassesByName(String className,HttpServletRequest request){
        List<Classes> classesList = classesService.queryClassesByClassName(className);
        request.setAttribute("classesList",classesList);
        return "/class-table";

    }
    @RequestMapping("/deleteClassesByID")
    private String deleteClassesByID(String classID,HttpServletRequest request){
        classesService.delClasses(Integer.parseInt(classID));
        List<Classes> classesList = classesService.queryClasses();
        request.setAttribute("classesList",classesList);
        return "/class-table";
    }
}
